package vn.com.epi.re.tools;

import java.io.Closeable;
import java.io.IOException;
import java.util.List;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HTableInterface;
import org.apache.hadoop.hbase.client.Increment;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Row;
import org.apache.hadoop.hbase.client.RowLock;
import org.apache.hadoop.hbase.client.Scan;

public class HTableWrapper implements HTableInterface, Closeable {

    private HTableInterface table;

    public HTableWrapper(HTableInterface table) {
        super();
        this.table = table;
    }

    public byte[] getTableName() {
        return table.getTableName();
    }

    public Configuration getConfiguration() {
        return table.getConfiguration();
    }

    public HTableDescriptor getTableDescriptor() throws IOException {
        return table.getTableDescriptor();
    }

    public boolean exists(Get get) throws IOException {
        return table.exists(get);
    }

    public void batch(List<Row> actions, Object[] results) throws IOException,
            InterruptedException {
        table.batch(actions, results);
    }

    /**
     * Allow this method to be call with List<Put>, List<Get>.
     */
    @SuppressWarnings({ "rawtypes", "unchecked" }) 
    public Object[] batch(List actions) throws IOException,
            InterruptedException {
        return table.batch(actions);
    }

    public Result get(Get get) throws IOException {
        return table.get(get);
    }

    public Result[] get(List<Get> gets) throws IOException {
        return table.get(gets);
    }

    @Deprecated
    public Result getRowOrBefore(byte[] row, byte[] family) throws IOException {
        return table.getRowOrBefore(row, family);
    }

    public ResultScanner getScanner(Scan scan) throws IOException {
        return table.getScanner(scan);
    }

    public ResultScanner getScanner(byte[] family) throws IOException {
        return table.getScanner(family);
    }

    public ResultScanner getScanner(byte[] family, byte[] qualifier)
            throws IOException {
        return table.getScanner(family, qualifier);
    }

    public void put(Put put) throws IOException {
        table.put(put);
    }

    public void put(List<Put> puts) throws IOException {
        table.put(puts);
    }

    public boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier,
            byte[] value, Put put) throws IOException {
        return table.checkAndPut(row, family, qualifier, value, put);
    }

    public void delete(Delete delete) throws IOException {
        table.delete(delete);
    }

    public void delete(List<Delete> deletes) throws IOException {
        table.delete(deletes);
    }

    public boolean checkAndDelete(byte[] row, byte[] family, byte[] qualifier,
            byte[] value, Delete delete) throws IOException {
        return table.checkAndDelete(row, family, qualifier, value, delete);
    }

    public Result increment(Increment increment) throws IOException {
        return table.increment(increment);
    }

    public long incrementColumnValue(byte[] row, byte[] family,
            byte[] qualifier, long amount) throws IOException {
        return table.incrementColumnValue(row, family, qualifier, amount);
    }

    public long incrementColumnValue(byte[] row, byte[] family,
            byte[] qualifier, long amount, boolean writeToWAL)
            throws IOException {
        return table.incrementColumnValue(row, family, qualifier, amount,
                writeToWAL);
    }

    public boolean isAutoFlush() {
        return table.isAutoFlush();
    }

    public void flushCommits() throws IOException {
        table.flushCommits();
    }

    /**
     * Implement Closeable interface so that it can be close similar to streams.
     */
    public void close() throws IOException {
        table.close();
    }

    public RowLock lockRow(byte[] row) throws IOException {
        return table.lockRow(row);
    }

    public void unlockRow(RowLock rl) throws IOException {
        table.unlockRow(rl);
    }
    
}
